package com.naiterui.ehp.bs.wechat.protocol.msg.custom;

import java.io.Serializable;

import org.apache.commons.lang3.builder.ToStringBuilder;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.naiterui.ehp.bs.wechat.constants.WeChatConstant;
import com.naiterui.ehp.bs.wechat.protocol.msg.IPoster;

/**
 * @Description: 向公众号发送客服消息
 * @Author: zhoupeipei
 * @Date： 2019/1/30
 */
public class CustomMsg<T> implements IPoster, Serializable {
    private static final long serialVersionUID = -1576968249218238290L;

    /**
     * 目标用户openID
     */
    @JsonProperty("touser")
    private String toUser;
    /**
     * 消息类型
     */
    @JsonProperty("msgtype")
    private String msgType;
    /**
     * 消息数据
     */
    private T data;

    public CustomMsg(String openId, T data, String msgType) {
        super();
        toUser = openId;
        this.data = data;
        this.msgType = msgType;
    }

    public String getToUser() {
        return toUser;
    }

    public void setToUser(String toUser) {
        this.toUser = toUser;
    }

    public String getMsgType() {
        return msgType;
    }

    public void setMsgType(String msgType) {
        this.msgType = msgType;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * 文本消息内容
     *
     * @return
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public T getText() {
        if (WeChatConstant.KefuMsgType.TEXT.equals(msgType)) {
            return data;
        } else {
            return null;
        }
    }

    /**
     * 图片消息
     *
     * @return
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public T getImage() {
        if (WeChatConstant.KefuMsgType.IMAGE.equals(msgType)) {
            return data;
        } else {
            return null;
        }
    }

    /**
     * 语音消息
     *
     * @return
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public T getVoice() {
        if (WeChatConstant.KefuMsgType.VOICE.equals(msgType)) {
            return data;
        } else {
            return null;
        }
    }

    /**
     * 小程序卡片
     *
     * @return
     */
    @JsonProperty("miniprogrampage")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public T getMiniProgramPage() {
        if (WeChatConstant.KefuMsgType.MINIPROGRAMPAGE.equals(msgType)) {
            return data;
        } else {
            return null;
        }
    }

    /**
     * 视频
     *
     * @return
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public T getVideo() {
        if (WeChatConstant.KefuMsgType.VIDEO.equals(msgType)) {
            return data;
        } else {
            return null;
        }
    }

    /**
     * 音乐
     *
     * @return
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public T getMusic() {
        if (WeChatConstant.KefuMsgType.MUSIC.equals(msgType)) {
            return data;
        } else {
            return null;
        }
    }

    /**
     * 图文消息（跳转到外链）
     *
     * @return
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public T getNews() {
        if (WeChatConstant.KefuMsgType.NEWS.equals(msgType)) {
            return data;
        } else {
            return null;
        }
    }

    /**
     * 图文消息(跳转到图文消息页面)
     *
     * @return
     */
    @JsonProperty("mpnews")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public T getMpNews() {
        if (WeChatConstant.KefuMsgType.MPNEWS.equals(msgType)) {
            return data;
        } else {
            return null;
        }
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
